<template>
    <div>
        <div style="margin-top: 1%">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item >首页</el-breadcrumb-item>
                <el-breadcrumb-item>采购订单</el-breadcrumb-item>
                <el-breadcrumb-item>新增</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <el-form :model="form" :rules="rules" ref="ruleform" label-width="140px">
                  <el-row>
                      <el-col :span="12">
                          <el-form-item label="部门"  prop="bumen">
                              <el-input v-model="form.bumen" autocomplete="off"></el-input>
                          </el-form-item>
                      </el-col>
                      <el-col :span="12">
                          <el-form-item label="单据编号"  prop="djbh" >
                              <el-input v-model="form.djbh"type="number" autocomplete="off"></el-input>
                          </el-form-item>
                      </el-col>
                  </el-row>

            <el-row>
                <el-col :span="12">
                    <el-form-item label="供应商"  prop="gys">
                        <el-input  v-model="form.gys" autocomplete="off"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="规格型号"  prop="ggxh">
                        <el-input  v-model="form.ggxh" autocomplete="off"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>

              <el-col :span="12">
                <el-form-item label="交货日期"  prop="jhrq">
                  <el-date-picker
                    v-model="form.jhrq"
                    type="datetime"
                    format="yyyy-MM-dd HH:mm:ss"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    default-time="12:00:00"
                    placeholder="选择日期时间">
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="数量"  prop="suliang">
                  <el-input  v-model="form.suliang"type="number" autocomplete="自动计算"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="实际含税单价"  prop="sjhsdj">
                        <el-input  v-model="form.sjhsdj" type="number" autocomplete="off"></el-input>
                    </el-form-item>
                </el-col>

              <el-col :span="12">
                <el-form-item label="价税合计" >
                  <el-input  v-model="form.jshj":readonly="true"  type="number"autocomplete="off"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="物料代码"  prop="wlzdm">
                        <el-input  v-model="form.wlzdm"type="number" autocomplete="off"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="物料名称"  prop="wlmc">
                        <el-input  v-model="form.wlmc" autocomplete="off"></el-input>
                    </el-form-item>
                </el-col>
            </el-row> <el-row>

                <el-col :span="12">
                    <el-form-item label="制单人"  prop="zdr">
                        <el-input  v-model="form.zdr" autocomplete="off"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="resetForm">重 置</el-button>
            <el-button type="primary" @click="handleConfine">确 定</el-button>
        </div>
    </div>
</template>

<script>
  import Cgdd from "../../../api/CgddApi";

  export default {
    name: 'index',
    data(){
      return{
        form: {
          bumen: '',
          djbh: '',
          gys: '',
          ggxh: '',
          sjhsdj: '',
          suliang: '',
          jshj: '',
          wlzdm: '',
          wlmc: '',
          zdr: '',

        },
        labelWidth:'100px',
        rules: {
          bibie: [
            { required: true, message: '币别', trigger: 'blur' },
          ],
          btfjs: [
            { required: true, message: '表体附件数', trigger: 'blur' },
          ],
          bumen: [
            { required: true, message: '部门', trigger: 'blur' },
          ],
          djbh: [
            { required: true, message: '单据编号', trigger: 'blur' },
          ],
          danwei: [
            { required: true, message: '单位', trigger: 'blur' },
          ],fjs: [
            { required: true, message: '附件数', trigger: 'blur' },
          ],gys: [
            { required: true, message: '供应商', trigger: 'blur' },
          ],ggxh: [
            { required: true, message: '规格型号', trigger: 'blur' },
          ],jhlb: [
            { required: true, message: '计划类别', trigger: 'blur' },
          ],jshj: [
            { required: true, message: '价税合计', trigger: 'blur' },
          ],jhrq: [
            { required: true, message: '交货日期', trigger: 'blur' },
          ],riqi: [
            { required: true, message: '日期', trigger: 'blur' },
          ],sjhsdj: [
            { required: true, message: '实际含税单价', trigger: 'blur' },
          ],slsl: [
            { required: true, message: '收料数量', trigger: 'blur' },
          ],suliang: [
            { required: true, message: '数量', trigger: 'blur' },
          ],zdr: [
            { required: true, message: '制单人', trigger: 'blur' },
          ],wlzdm: [
            { required: true, message: '物料长代码', trigger: 'blur' },
          ],wlmc: [
            { required: true, message: '物料名称', trigger: 'blur' },
          ],
        }
      }
    },
    computed:{
      jiner(){
        return this.form.sjhsdj*this.form.suliang
      }

    },
    watch:{
      jiner(val) {
        this.form.jshj = val;
      },
    },
    methods:{
      //确认添加
      handleConfine() {
        var validate = false;
        this.$refs['ruleform'].validate((valid) => {
          if (valid) {
            validate = true;
          } else {
            console.log('error submit!!');
            validate = false;
            return false;
          }
        });
        if (validate === false) {
          return;
        }
        // let newData = this.changeDate(this.form.dhrq)
        // let newData = this.form.dhrq

        let data = {
          bumen: this.form.bumen,//部门
          djbh: this.form.djbh,//单据编号
          gys: this.form.gys,//供应商
          ggxh: this.form.ggxh,//规格型号
          sjhsdj:this.form.sjhsdj,//实际含税单价
          suliang: this.form.suliang,//数量
          jshj:this.form.jshj,//价税合计
          wlzdm:this.form.wlzdm,//物料代码
          wlmc: this.form.wlmc,//物料名称
          zdr:this.form.zdr,//制单人
          jhrq:this.form.jhrq,//交货日期
        }

        Cgdd.add(data)
          .then(res => {
            // 返回数据
            if(res.flag){
              this.$message.success("添加成功!");
              this.form  = {
                bumen: '',
                djbh: '',
                gys: '',
                ggxh: '',
                sjhsdj: '',
                suliang: '',
                jshj: '',
                wlzdm: '',
                wlmc: '',
                zdr: '',
              }
            }
            this.showAddDialog = false;
          })
          .catch(err => {
            // 异常情况
          })

      },
      resetForm() {
        this.$refs['ruleform'].resetFields();
      },
    }
  };
</script>

<style scoped>

</style>
